#include "stdio.h"
// 选择排序
//依次把最大的，第二大的...选出来放到对应位置上，时间复杂度O(n2),空间O(1)

void Swap(int *a, int *b)
{
    int c = *a;
    *a = *b;
    *b = c;
}
void Print_Array(int *a, int n)
{
    printf("排序后的数组为:\r\n");
    for (int i = 0; i < n; i++)
    {
        printf("%d ", *a);
        a++;
    }
}
void Select_Sort(int *array,int n)
{
    for (int i = 0; i < n; i++)
    {
        for (int j = i; j < n; j++)
        {
            if (array[i] < array[j])
                Swap(&array[i], &array[j]);
        }
    }
}
int main()
{
    int array[10] = {1, 3, 2, 4, 0, 9, 8, 7, 5, 6};
    Select_Sort(array,sizeof(array) / sizeof(array[0]));
    Print_Array(array, 10);
}